package leetcode.每日一题;

import org.junit.Test;

import java.util.*;

/**
 * @author ：zsy
 * @date ：Created 2021/12/21 21:42
 * @description：https://leetcode-cn.com/problems/day-of-the-year/
 */
public class 一年中的第几天 {
    @Test
    public void test() {
        Solution solution = new Solution();
        System.out.println(solution.dayOfYear( "2003-03-01"));
    }

    class Solution {
        public int dayOfYear(String date) {
            String[] strings = date.split("-");
            Calendar calendar = new GregorianCalendar();
            calendar.set(Integer.parseInt(strings[0]), Integer.parseInt(strings[1]) - 1, Integer.parseInt(strings[2]));
            long curTime = calendar.getTime().getTime();
            calendar.set(Integer.parseInt(strings[0]), Calendar.JANUARY, 1);
            long preTime = calendar.getTime().getTime();
            int ans = (int) ((curTime - preTime) / 1000 / 60 / 60 / 24) + 1;
            return ans;
        }
    }
}
